<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/include/head.jsp"%>
<table id="dg" >
</table>

<div id="queryDialog" class="easyui-dialog" title="查询" style="width: 500px; height: 400px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#searchbb'">  
            <form action="" id="searchForm">
	            <table cellpadding="0" cellspacing="1" class="formtable">
								<tr>
				<td align="right"><label class="Validform_label">订单编号:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="orderCode" name="orderCode"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">产品名称:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="productName" name="productName"/>
				</td>
				</tr>
				  
				<tr>
				<td align="right"><label class="Validform_label">客户名称:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="cusName" name="cusName"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">订单日期:</label></td>
				<td class="value">
					<input class="easyui-datebox" type="text"  id="orderTime" name="orderTime"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">收货日期:</label></td>
				<td class="value">
					<input class="easyui-datebox" type="text"  id="recvDate" name="recvDate"/>
				</td>
				</tr>
				 
				<tr>
				<td align="right"><label class="Validform_label">仓库:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="depot" name="depot"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">状态:</label></td>
				<td class="value">
					<select id="status" class="easyui-combobox" name="status" style="width:200px;" data-options="required:true">  
				    <option value="" >所有</option>   
					<option value="1" >到货</option>    
				    <option value="0" selected="selected">未到货</option>   
				</select>
				</td>
				</tr>
	            </table>  
            </form>
            <div style="text-align:right;margin-right:30px;"  id="searchbb">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="btnSearch()">查询</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="btnSearchCancel()">取消</a>  
            </div>                  
</div>
<div id="importDialog" class="easyui-dialog" title="查询" style="width: 400px; height: 260px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#btnimport'">
                 
                 <form action="" id="importForm" method="post"  enctype="multipart/form-data">
	            <table cellpadding="0" cellspacing="1" class="formtable">
								<tr>
				<td align="right"><label class="Validform_label">文件:</label></td>
				<td class="value">
					<input  type="hidden"  id="importType" name="importType" value="1"/>
					<input class="easyui-filebox" type="text"  id="file" name="file" data-options="required:true"/>
				</td>
				</tr>
				</table>  
			</form>
<div style="text-align:right;margin-right:30px;"  id="btnimport">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="doimport()">确定</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="cancelimport()">取消</a>  
 </div>  
</div>   



<script type="text/javascript">
	$(function() {
		initCurdDatagrid('pOrder','dg',{
			title:'进货单',
			baseUrl:'',
			dwidth:'90%',//弹出对话框的宽度 百分比或者具体数字宽度
			dheight:'90%',//弹出对话框的高度 百分比或者具体数字宽度
			queryParams:$("#searchForm").serializeObject(),
			sortName:'orderTime',
			sortOrder:'desc',
			multiSort:false,
			columns:[[    
				        {field:'orderCode',title:'订单编号',width:200,sortable:true},    
				        {field:'productId',title:'产品ID',width:100,sortable:true,hidden:true},    
				        {field:'productName',title:'产品名称',width:140,sortable:true},    
				        {field:'unit',title:'单位',width:40,sortable:true},    
				        {field:'productNum',title:'数量',width:60,sortable:true},    
				        {field:'unitPrice',title:'单价',width:60,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        },hidden:true},    
				        {field:'totalPrice',title:'总价',width:100,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        },hidden:true},    
				        {field:'freight',title:'运费',width:60,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        },hidden:true},    
				        {field:'discountPrice',title:'调整金额',width:60,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        },hidden:true},    
				        {field:'finnalUnitPrice',title:'成交单价',width:60,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        }},    
				        {field:'finnalPrice',title:'实付金额',width:60,sortable:true,formatter:function(value,row,idx){
				        	return value.toFixed(2);
				        }},   
				        {field:'cusId',title:'客户ID',width:100,sortable:true,hidden:true},    
				        {field:'cusName',title:'客户名称',width:100,sortable:true},    
				        {field:'orderTime',title:'订单日期',width:100,sortable:true,hidden:true}, 
				        {field:'expRecvDate',title:'预计收货日期',width:100,sortable:true,formatter:function(value){
				        	if(value && value.length > 10)
				        		return value.substring(0,10);
				        	else
				        		return value;
				        }},    
				        {field:'expRecvRemark',title:'预计到货跟踪',width:100,sortable:true},   
				        {field:'recvDate',title:'收货日期',width:100,sortable:true,formatter:function(value){
				        	if(value && value.length > 10)
				        		return value.substring(0,10);
				        	else
				        		return value;
				        }},    
				        {field:'remark',title:'remark',width:100,sortable:true,hidden:true},    
				        {field:'depot',title:'仓库',width:100,sortable:true},    
				        {field:'status',title:'状态',width:100,sortable:true,formatter:function(value,row,idx){
				        	return value==0?'<span clore="red">未到货</span>':'已到货';
				        },styler:function(value,row,idx){
				        	return value==0?'color:red':'color:black';
				        }}    
				    ]] 
		},[{
			text: '导入阿里', 
	        iconCls: 'icon-add', 
	        handler: function() { 
	        	$("#importType").val("0");
	        	$("#importDialog").dialog('open');
	        } 
		},'-',{
			text: '导入', 
	        iconCls: 'icon-add', 
	        handler: function() { 
	        	$("#importType").val("1");
	        	$("#importDialog").dialog('open');
	        } 
		},'-',{
			text: '填写预计到货日期', 
	        iconCls: 'icon-edit', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
	    		if(selArr.length < 1)
	    		{
	    			$.messager.alert("验证结果","请选中一行数据",'error');
	    			return;
	    		}
	    		for(var i =0; i < selArr.length; i++)
	    		{
	    			var val = selArr[i];
	    			if(val.status != 0)
	    			{
	    				$.messager.alert("验证结果","请选择未收货数据",'error');
		    			return false;
	    			}
	    		}
			     $("#setExpRecvDateDialog").dialog('open');
	        } 
		},'-',{
			text: '导出到货计划表', 
	        iconCls: 'icon-export', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
	    		if(selArr.length < 1)
	    		{
	    			$.messager.alert("验证结果","请选中一行数据",'error');
	    			return;
	    		}
	    		var ids = "";
	    		var ids = "";
	    		$.each(selArr, function(i,val){      
	    			ids += "," + val.id;
	    		 });
	    		
			    window.open("${ctx}/ReportServer?reportlet=htje%2Fdhrq.cpt&ids="+ids.substring(1));
	        } 
		},'-',{
			text: '签收', 
	        iconCls: 'icon-edit', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
	    		if(selArr.length < 1)
	    		{
	    			$.messager.alert("验证结果","请选中一行数据",'error');
	    			return;
	    		}
	    		for(var i =0; i < selArr.length; i++)
	    		{
	    			var val = selArr[i];
	    			if(val.status != 0)
	    			{
	    				$.messager.alert("验证结果","请选择未收货数据",'error');
		    			return false;
	    			}
	    		}
			     $("#setRecvDateDialog").dialog('open');
	        } 
		},'-',{
			text: '取消签收', 
	        iconCls: 'icon-cancel', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
	    		if(selArr.length < 1)
	    		{
	    			$.messager.alert("验证结果","请选中一行数据",'error');
	    			return;
	    		}
	    		var ids = "";
	    		$.each(selArr, function(i,val){      
	    			ids += "," + val.id;
	    		 });
	    		$.messager.confirm('提示', '您确定要删除吗？',
	    				function(flag) {
	    					if (flag) {
	    						KD.ajax({
	    			    			url:'cacelSign.do',
	    			    			data:{ids:ids.substring(1)},
	    			    			success:function(){
	    			    				$.messager.alert("验证结果","取消成功",'info',function(){
	    			    					$('#dg').datagrid('reload');
	    			    				});
	    			    			}
	    			    		});    
	    					}
	    				});
	    		
	        } 
		},'-',{
			text: '添加备注', 
	        iconCls: 'icon-add', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
	    		if(selArr.length != 1)
	    		{
	    			$.messager.alert("验证结果","请选中一行数据",'error');
	    			return;
	    		}
	    		var id  = selArr[0].id;
	    		$.messager.prompt('提示信息', '请输入：', function(r){
	    			if (r){
	    				$.messager.progress(); 
	    				KD.ajax({
			    			url:'addRemark.do',
			    			data:{id:id,remark:r},
			    			success:function(){
			    				$.messager.alert("设置结果","设置成功",'info',function(){
			    					$.messager.progress('close');
			    					$('#dg').datagrid('reload');
			    				});
			    			}
			    		});   
	    			}
	    		});
	        } 
		}]);
		
		$('#importForm').form({    
		    url:'importOrder.do',   
		    iframe:false,
		    onSubmit: function(param){ 
		    	//do your things on submint
		    },    
		    success:function(data){    
		    	data = JSON.parse(data);
		    	if(data.result == '1')
		    	{
		    		$.messager.alert("保存结果","导入成功",'info',function(){
		    			cancelimport();
		    			$('#dg').datagrid('reload');
			    	});	
		    	}
		    	else
		    	{
		    		$.messager.alert("保存结果","导入失败：" + data.message,'error',function(){
		    			
			    	});
		    	}
		    }    
		});  
	});
	
	function doimport(){
		if(!$("#importForm").form('validate'))
		{
			$.messager.alert("验证结果","请选择文件",'error',function(){
	    	});
			return;
		}
		$("#importForm").submit();  
	}
	function cancelimport(){
		
		$("#importDialog").dialog('close');  
		
	}
	function btnSearchCancel()
	{
		$("#queryDialog").dialog('close');  
	}
	function btnSearch()
	{ 
		$('#dg').datagrid('load',$("#searchForm").serializeObject());
		$("#queryDialog").dialog('close');
	}
	
	function reloadData()
	{
		$('#dg').datagrid('reload');
	}
	function setRecvDate()
	{
		 		
		var selArr = $('#dg').datagrid('getSelections');
		if(selArr.length < 1)
		{
			$.messager.alert("验证结果","请选中一行数据",'error');
			return;
		}
		var ids = "";
		$.each(selArr, function(i,val){      
			ids += "," + val.id;
		 });
		if(!$("#setRecvDateForm").form('validate'))
		 {
				$.messager.alert("验证结果","表单验证失败",'error',function(){
		    	});
				return;
		 }	
		var data = {ids:ids.substring(1),
					recvDate:$('#recvDate_set').datebox('getValue'),
					depot:$('#depot_set').combobox('getValue'),
					remark:$('#remark_set').textbox('getValue')
				};
		if(!data.recvDate || data.recvDate == '')
		 {
				$.messager.alert("验证结果","表单验证失败",'error',function(){
		    	});
				return;
		 }	
		KD.ajax({
			url:'updateRecvDate.do',
			data:data,
			success:function(){
				$.messager.alert("验证结果","设置成功",'info',function(){
					$('#dg').datagrid('reload');
					cancelRecvDate();
				});
			}
		});
	}
	function cancelRecvDate(){
		$("#setRecvDateDialog").dialog('close');  
	}
	
	function setExpRecvDate()
	{
		var selArr = $('#dg').datagrid('getSelections');
		if(selArr.length < 1)
		{
			$.messager.alert("验证结果","请选中一行数据",'error');
			return;
		}
		var ids = "";
		$.each(selArr, function(i,val){      
			ids += "," + val.id;
		 });
		if(!$("#setExpRecvDateForm").form('validate'))
		 {
				$.messager.alert("验证结果","表单验证失败",'error',function(){
		    	});
				return;
		 }	
		var data = {ids:ids.substring(1),
					expRecvDate:$('#expRecvDate_set').datebox('getValue'),
					expRecvRemark:$('#expRecvRemark_set').textbox('getValue')
				};
		if(!data.expRecvDate || data.expRecvDate == '')
		 {
				$.messager.alert("验证结果","表单验证失败",'error',function(){
		    	});
				return;
		 }	
		KD.ajax({
			url:'updateExpRecvDate.do',
			data:data,
			success:function(){
				$.messager.alert("验证结果","设置成功",'info',function(){
					$('#dg').datagrid('reload');
					cancelExpRecvDate();
				});
			}
		});
	}
	function cancelExpRecvDate(){
		$("#setExpRecvDateDialog").dialog('close');  
	}
</script>
<div id="setRecvDateDialog" class="easyui-dialog" title="查询" style="width: 400px; height: 260px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#btnsetRecvDate'">
                 <form action="" id="setRecvDateForm">
                 
                 
	            <table cellpadding="0" cellspacing="1" class="formtable">
				 <tr>
				<td align="right"><label class="Validform_label">日期:</label></td>
				<td class="value">
					<input class="easyui-datebox" type="text"  id="recvDate_set" name="recvDate" data-options="required:true"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">仓库:</label></td>
				<td class="value">
					<select id="depot_set" class="easyui-combobox" name="depot" style="width:200px;" data-options="required:true">  
					<option value="虎池路" >虎池路</option>    
					<option value="新华工业区" >新华工业区</option>    
				    <option value="馨泰" >馨泰</option>   
				    <option value="曙光苑" >曙光苑</option>   
				</select>
				</td>
				</tr>
				 <tr>
				<td align="right"><label class="Validform_label">备注:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text" multiline='true' data-options="height:100"  id="remark_set" name="remark"  />
				</td>
				</tr>
				</table> 
				</form> 
<div style="text-align:right;margin-right:30px;"  id="btnsetRecvDate">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="setRecvDate()">确定</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="cancelRecvDate()">取消</a>  
 </div>  
</div>   

<div id="setExpRecvDateDialog" class="easyui-dialog" title="设置" style="width: 400px; height: 260px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#btnsetExpRecvDate'">
                 <form action="" id="setExpRecvDateForm">
                 
                 
	            <table cellpadding="0" cellspacing="1" class="formtable">
				 <tr>
				<td align="right"><label class="Validform_label">日期:</label></td>
				<td class="value">
					<input class="easyui-datebox" type="text"  id="expRecvDate_set" name="expRecvDate" data-options="required:true"/>
				</td>
				</tr>
				 <tr>
				<td align="right"><label class="Validform_label">备注:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text" multiline='true' data-options="height:100"  id="expRecvRemark_set" name="expRecvRemark"  />
				</td>
				</tr>
				</table> 
				</form> 
<div style="text-align:right;margin-right:30px;"  id="btnsetExpRecvDate">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="setExpRecvDate()">确定</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="cancelExpRecvDate()">取消</a>  
 </div>  
</div> 



           
<%@include file="/include/foot.jsp"%>